package com.Isb.Golf.inputgolfscore;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class CourseInputActivity extends Activity {

	private Button btn_next;
	private EditText textView_holePar[]= {null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
	private EditText textView_holeHDC[]= {null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};

    private InputGolfScoreModel appModel;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_course_input);

		appModel = InputGolfScoreModel.getInstance();

		findViews();
		setListeners();
	}

	protected void findViews(){
		btn_next = (Button)this.findViewById(R.id.button_next);
		int resId = R.id.editPar1;
		for(int n = 0; n < 9; n++, resId+=6){
			textView_holePar[n] = (EditText)this.findViewById(resId);
		}
		resId = R.id.editPar10;
		for(int n = 9; n < 18; n++, resId+=6){
			textView_holePar[n] = (EditText)this.findViewById(resId);
		}

		resId = R.id.editHDC1;
		for(int n = 0; n < 9; n++, resId+=6){
			textView_holeHDC[n] = (EditText)this.findViewById(resId);
		}
		resId = R.id.editHDC10;
		for(int n = 9; n < 18; n++, resId+=6){
			textView_holeHDC[n] = (EditText)this.findViewById(resId);
		}
	}

	protected void setListeners(){
		btn_next.setOnClickListener(new OnClickListener(){
			public void onClick(View v){
				for(int n = 0; n < 18; n++){
					CharSequence  seqPar = textView_holePar[n].getText();
					String strPar = seqPar.toString();

					CharSequence  seqHDC = textView_holeHDC[n].getText();
					String strHDC = seqHDC.toString();

					appModel.setcourseData(n, strPar, strHDC);
				}
//				Intent intent = new Intent();
//				intent.setClassName("com.Isb.Golf.inputgolfscore", "com.Isb.Golf.inputgolfscore.CourseInputActivity");
//				intent.setAction(Intent.ACTION_VIEW);
//				startActivity(intent);
			}
		});
	}
}
